package com.qxy.practice.concurrent;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.FutureTask;

/**
 * @author : 戚欣扬
 * @Description :
 */
public class CyclicBarrierDemo {

    public static void main(String[] args) {
        CyclicBarrier collect = new CyclicBarrier(7,()->{
            System.out.println("召唤神龙！超级赛亚人之神！！！");
        });
        for (int i = 1; i <8; i++) {

            int finalI = i;
            new Thread(()->{
                System.out.println("已经收集龙珠 ：" + finalI);
                try {
                    collect.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } catch (BrokenBarrierException e) {
                    throw new RuntimeException(e);
                }
            },String.valueOf(i)).start();
        }

    }
}


